<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>用户抽奖列表</title>
    <link rel="stylesheet" type="text/css" th:href="@{/js/layui/css/layui.css}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/fyn/style.css/}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/fyn/my.css/}" media="all">

</head>
<body class="body">

<div class="my-btn-box layui-form">
    <span class="fr">
        <div class="layui-input-inline">
            <input type="text" autocomplete="off" name="prizeName" placeholder="奖品名称" class="layui-input height33">
        </div>
        <div class="layui-input-inline">
            <input type="text" autocomplete="off" name="userId" placeholder="用户ID" class="layui-input height33">
        </div>
        <div class="layui-input-inline">
            <input type="text" autocomplete="off" name="nickName" placeholder="用户昵称" class="layui-input height33">
        </div>
         <div class="layui-input-inline">
             <select name="status" id="statusId" lay-filter="status">
                <option value="">请选择状态</option>
                <option value="0">已中奖</option>
                <option value="1">已发货</option>
              </select>
        </div>
        <div class="layui-input-inline">
              <input type="text" name="createTime" autocomplete="off" class="layui-input height33"
                     id="rtimeId"  placeholder="中奖时间">
        </div>
        <div class="layui-input-inline">
              <input type="text" name="shipmentTime" autocomplete="off" class="layui-input height33"
                     id="stimeId"  placeholder="发货时间">
          </div>
        <button class="layui-btn layui-btn-sm" id="search"><i class="layui-icon">&#xe615;</i></button>
    </span>
</div>

<!-- 表格 -->
<div id="dateTable" lay-filter="event"></div>
<div class="height50"></div>
<script th:src="@{/js/layui/layui.js}"></script>
<script th:src="@{/js/fyn/index.js}"></script>
<script th:src="@{/js/fyn/my.js}"></script>
<script type="text/javascript" th:src="@{/js/vip/vip_comm.js}"></script>
<script type="text/javascript" th:src="@{/js/vip/vip_table.js}"></script>
<script type="text/javascript" th:inline="javascript">

    // layui方法
    layui.use(['table', 'form', 'laypage', 'layer', 'laydate'], function () {

        // 操作对象
        var form = layui.form
            , table = layui.table
            , layer = layui.layer
            , laydate = layui.laydate
            , $ = layui.jquery;

        //中奖时间
        var rtimeId = laydate.render({
            elem: '#rtimeId',
            type: 'date',
            format: 'yyyy-MM-dd',
            trigger:'click',
            value: '',
            done: function(value, date){
            }
        });

        //发货时间
        var stimeId = laydate.render({
            elem: '#stimeId',
            type: 'date',
            format: 'yyyy-MM-dd',
            trigger:'click',
            value: '',
            done: function(value, date){
            }
        });

        // 表格渲染
        var tableIns = table.render({
            elem: '#dateTable'                  //指定原始表格元素选择器（推荐id选择器）
            , height: "full"    //容器高度
            // , skin: 'line'
            , even: 'true'
            , cols: [[                  //标题栏
                {field: 'userId', title: '用户ID', minWidth: '80', align: 'center'},
                {field: 'nickName', title: '用户昵称', minWidth: '80', align: 'center'},
                {field: 'prizeName', title: '奖品名称', minWidth: '80', align: 'center'},
                {
                    field: 'status', title: '状态', align: 'center', minWidth: '100', templet: function (d) {
                        if (d.status == 0) {
                            return "<button class='layui-btn layui-btn-normal layui-btn-xs'>已中奖</button>";
                        }
                        return "<button class='layui-btn layui-btn-danger layui-btn-xs'>已发货</button>";
                    }
                }
                , {
                    field: 'createTime',
                    align: 'center',
                    title: '中奖时间',
                    sort: true,
                    minWidth: '200',
                    templet: function (d) {
                        return d.createTime;
                    }
                }
                , {
                    field: 'shipmentTime',
                    align: 'center',
                    title: '发货时间',
                    sort: true,
                    minWidth: '200',
                    templet: function (d) {
                        if (d.shipmentTime) {
                            return d.shipmentTime;
                        }
                        return '';
                    }
                },
                {field: 'logistics', title: '发货备注', minWidth: '180', align: 'center'},
                {title: '操作', align: 'center', toolbar: '#barOption'}
            ]]
            , id: 'dataCheck'
            , url: [[${basePath}]] + '/lottery/queryRedeemedLotteryList'
            , method: 'get'
            , page: true
            , limits: [10, 30, 60, 90, 150, 300]
            , toolbar: '#topOperate'
            , limit: 10 //默认采用0
            , loading: true
            // , where: {name: $("input[name='name']").val()}
            , done: function (res, curr, count) {
                //如果是异步请求数据方式，res即为你接口返回的信息。
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                $("td[data-field='content']").each(function () {
                    $(this).find(".layui-table-cell").removeClass('layui-table-cell');
                });


            }
        });


        table.on('tool(event)', function (obj) {
            var data = obj.data;
            if (obj.event === 'shipment') {
                layer.prompt({
                    formType: 0,
                    value: data.logistics,
                    title: '请输入物流信息',
                    area: ['800px', '350px'] //自定义文本域宽高
                }, function (value, index, elem) {
                    $.ajax({
                        type: "post",
                        url: [[${basePath}]] + "/lottery/redeemedLotteryShipment",
                        data: {
                            id: data.id,
                            logistics: value
                        },
                        success: function (res) {
                            layer.close(index);
                            if (res.success) {
                                layer.msg(res.msg, {icon: 1}, 2000);
                                setTimeout(function () {
                                    tableIns.reload()
                                }, 2000);
                            } else {
                                layer.msg(res.msg, {icon: 2}, 2000);
                            }
                        }
                    });
                });

            }
        });

        $("#search").click(function () {
            tableIns.reload({
                where: {
                    prizeName: $("input[name='prizeName']").val()
                    ,userId: $("input[name='userId']").val()
                    ,nickName: $("input[name='nickName']").val()
                    ,status: $("#statusId").find("option:selected").val()
                    ,createTime: $("#rtimeId").val()
                    ,shipmentTime: $("#stimeId").val()
                },
                page: {
                    curr: 1
                }
            });
        })


    });
</script>
<!-- 表格操作按钮集 -->
<script type="text/html" id="barOption">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="shipment"><i class="layui-icon"></i>发货</a>
</script>
</body>
</html>